package com.haoshuang.zhouzhoubang.ui.page.order.time
import androidx.recyclerview.widget.GridLayoutManager
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ItemTime99Binding
import com.haoshuang.zhouzhoubang.model.bean.TimeBean99
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter
import com.mufeng.libs.core.setOnItemClick
import com.mufeng.libs.utils.view.gone
import com.mufeng.libs.utils.view.visible
import java.util.*

/**
 * 订单模块中的订单列表适配器
 * */
class TimeAllAdapter(data: MutableList<TimeBean99>, private var is_team: String = "0") :
    BaseBindingQuickAdapter<TimeBean99, ItemTime99Binding>(data) {
    var act: UpdateServiceTimeActivity? = null

    override fun onBindViewHolder(holder: BaseBindingHolder, position: Int, item: TimeBean99?) {
        val binding = ItemTime99Binding.bind(holder.itemView)
        if (act == null) {
            act = context as UpdateServiceTimeActivity
        }

        binding.apply {
            if (item?.isCheck==0){
                rvList22.gone()
            }else{
                rvList22.visible()
            }
            if (item?.isCheck2==0){
                tvTime1.gone()
            }else{
                tvTime1.visible()
            }

            var adapter3= TimeCheckAdapter22(item!!.list2)
            var lan= GridLayoutManager(context,3)

            rvList22.layoutManager=lan
            rvList22.adapter=adapter3
            adapter3.setOnItemClick { view, position, item1 ->
                var bean=item.list2[position]
                if (bean.isCheck!=2){
                    if (bean.is_full==0 || is_team == "1"){
                        if (bean.isCheck==0){
                            for (b in item.list2){
                                if (b.isCheck!=2)
                                    b.isCheck=0
                            }
                            item.list2[position].isCheck=1
                            var service_time=  item.list2[position].service_time
                            act?.MyTime(service_time)
                            adapter3.notifyDataSetChanged()
                        }else{
                            item.list2[position].isCheck=0
                            var service_time=""
                            act?.MyTime(service_time)
                            adapter3.notifyDataSetChanged()
                        }
                    }
                }

            }
            var adapter2 = Time10Adapter(item.timeList)
            tvTime1.text = item.riqi
            rvList2.layoutManager = GridLayoutManager(context, 7)
            rvList2.adapter = adapter2
            adapter2.setOnItemClick { view, position, item2 ->

                var bean=item.timeList[position]
                if (item.timeList[position].isCheck != 1){

                    act?.setZc(holder.layoutPosition, position,"${bean.year}-${bean.month}-${bean.day}")
                }

            }

        }
    }
}